package cn.ad.server.web.servlet;

import cn.ad.server.web.servlet.v2.RestPathFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author dongbin.yu
 * @from 2016-07-18
 * @deprecated 原广告请求处理Servlet框架将不推荐使用，统一采用v2包下的处理方式，请求入口参考{@link RestPathFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)}
 */
@Deprecated
@WebServlet("/bid.html")
public class RTBRequestServlet extends AbstractBidServlet {

	private final static Logger logger = LoggerFactory.getLogger(RTBRequestServlet.class);

	// @Benchmark
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException {

		try {
			request.getRequestDispatcher("/v2/bid/ch/2").forward(request, response);
		} catch (ServletException e) {
			logger.error("ServletException", e);
		} catch (IOException e) {
			logger.error("IOException", e);
		}
		return;

		// // 是否采用流量过滤
		// if (adService.checkflowFilter()) {
		// response.setStatus(204);
		// return;
		// }
		//
		// try (ServletOutputStream outputStream = response.getOutputStream()) {
		// //request.getRequestDispatcher("/v2/bid/ch/2").forward(request,
		// response);
		//
		// String id = request.getParameter("id");
		// response.setContentType("application/json;charset=utf-8");
		// if (StringUtils.hasText(id)) {
		// BidProcessor bidProcessor =
		// SpringContextUtils.getBean(Exchange.exchangeMap.get(id),
		// BidProcessor.class);
		// BidAdResponse bidResponse = null;
		// bidResponse = bidProcessor.process(request, response);
		// if (bidResponse == null) {
		// response.setStatus(204);
		// } else {
		// objectMapper.writeValue(outputStream, bidResponse);
		// }
		//
		// } else {
		// response.setStatus(204);
		// }
		// } catch (Exception e) {
		// logger.error("/bid.html?id=2 ERROR - {}", e);
		// }
	}
}
